﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewCustomerSelector.aspx.cs"
    Inherits="UI_NewCustomerSelector" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link href="/images/style.css" rel="Stylesheet" />

    <link href="/js/ztree/zTreeStyle.css" rel="Stylesheet" />
    <script language="javascript" type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>
    <script language="javascript" type="text/javascript" src="/js/ztree/jquery.ztree.all-3.4.min.js"></script>
    <script type="text/javascript">
		<!--
        var setting = {
            async: {
                enable: true,
                url: getUrl,
                dataFilter: dataFilter
            },
            view: {
                expandSpeed: ""
            },
            callback: {
                onCheck: onCheck,
                beforeExpand: beforeExpand,
                onAsyncSuccess: onAsyncSuccess,
                onAsyncError: onAsyncError
            },
            check: {
            autoCheckTrigger: true,
                enable: true
            },
            chkboxType: { "Y": "ps", "N": "ps" },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };

        var zNodes = [
		  <%=getCustomerGroup() %>
 		];



        $(document).ready(function () {
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);
            
        });

        var perTime = 100;
        var perCount = 50;
        function getUrl(treeId, treeNode) {
            var times = treeNode.times;
            var url = "/ui/getCustomerList.aspx?type=ajax&times=" + times + "&count=" + perCount + "&groupid=" + treeNode.id;
            return url;
        }
        function dataFilter(treeId, parentNode, childNodes) {
			if (parentNode.checkedEx === true) {
				for(var i=0, l=childNodes.length; i<l; i++) {
					childNodes[i].checked = parentNode.checked;
					childNodes[i].halfCheck = false;
					childNodes[i].checkedEx = true;
				}
			}
			return childNodes;
		}
        function onCheck(event, treeId, treeNode) {
			cancelHalf(treeNode)
			treeNode.checkedEx = true;
		}
		 
		function cancelHalf(treeNode) {
			if (treeNode.checkedEx) return;
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			treeNode.halfCheck = false;
			zTree.updateNode(treeNode);			
		}
        function beforeExpand(treeId, treeNode) {
            if (!treeNode.isAjaxing) {
                treeNode.times = 1;
                ajaxGetNodes(treeNode, "refresh");
                return true;
            } else {
                alert("zTree 正在下载数据中，请稍后展开节点。。。");
                return false;
            }
        }
        function onAsyncSuccess(event, treeId, treeNode, msg) {
            if (!msg || msg.length == 0) {
                return;
            }
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            totalCount = treeNode.count;
            if (treeNode.children.length < totalCount) {
                setTimeout(function () { ajaxGetNodes(treeNode); }, perTime);
            } else {
                treeNode.icon = "";
                zTree.updateNode(treeNode);
                zTree.selectNode(treeNode.children[0]);

            }
        }

        function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            alert("异步获取数据出现异常。");
            treeNode.icon = "";
            zTree.updateNode(treeNode);
        }
        function ajaxGetNodes(treeNode, reloadType) {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            if (reloadType == "refresh") {
                treeNode.icon = "/js/zTree/img/loading.gif";
                zTree.updateNode(treeNode);
            }
            zTree.reAsyncChildNodes(treeNode, reloadType, true);
            treeNode.times = treeNode.times + 1;
        }


        

        function go() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            var nodes = treeObj.getCheckedNodes(true);
             var chk_value=""  ;
             var chk_name="" ;
              
            $.each(nodes, function (index) {
                if (nodes[index].tel != '0') {
                 chk_value=chk_value+nodes[index].id+",";
                 chk_name=chk_name+nodes[index].customername+",";
                                    
                }
           
            });
             if (chk_value.length  > 0) {
                window.returnValue = chk_name + "--" + chk_value;  //返回值
                window.close();
            }
            else {
                alert("请至少选择一项,按客户级别选择的话请点开前面的+号");
            }
        }
		//-->
    </script>
</head>
<body style="overflow-x: hidden">
    <form id="form1" runat="server">
    <table width="100%" class="tableBorder" border='1' cellspacing="0" style="border-collapse: collapse;"
        bgcolor="#ffffff" bordercolor="#cccccc">
        <tr align="center" valign="middle">
            <th height="22">
                客户选择
            </th>
        </tr>
        <tr>
            <td>
                <input type="button" value="确定" onclick="go()" class="btn">
            </td>
        </tr>
        <tr>
            <td>
                <div>
                    <ul id="treeDemo" class="ztree">
                    </ul>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="确定" onclick="go()"  class="btn">
            </td>
        </tr>
        </table>
    </form>
</body>
</html>
